﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.MessageProxy;
using TestESBProxy.Messages;
using PServiceBus.Transports;

namespace TestESBProxy {

    [ESBProxyService]
    public interface IChatService {

        [ESBTransport(typeof(TcpTransport))]
        [ESBTransportParam("Port", "1111")]
        [ESBTransportParam("IPAddress", "127.0.0.1")]
        [ESBRequest(typeof(ChatRequest), isRequestClass: true)]
        ChatResponse Execute(ChatRequest request);
    }

    class Program {
        static void Main(string[] args) {

            ProxyService.Start();

            var service = ProxyService.Create<IChatService>();

            Console.WriteLine("Press enter to send request. Type exit to close");

            while (true) {
                var text = Console.ReadLine();
                if (text.ToLower() == "exit") break;
                var response = service.Execute(new ChatRequest() { Message = "Hello Server", UserName = "Client" });
                if (response != null)
                    Console.WriteLine("{0}: {1}", response.UserName, response.Message);
                else
                    Console.WriteLine("Could not process request");
            }

            ProxyService.Shutdown();
        }
    }
}
